﻿using System;
using System.Collections.Generic;
using System.Text;
using CYTools.Util;
using System.Data;
using System.Data.SqlClient;
using CYTools.Models.Model;

namespace CYTools.Models.Dao
{
    public class YclInfoDao
    {
        public Database db = new Database();
        /// <summary>
        /// 获取系列表信息
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        public List<XilieInfo> getXlInfoList(SqlConnection conn)
        {
            List<XilieInfo> XlInfoList = new List<XilieInfo>();
            string sql = "SELECT XL_id,Cj_id,Mingcheng  FROM 系列 where XL_id <>1";
            try
            {
                DataTable dt = db.Squery(sql, conn);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        XilieInfo ui = new XilieInfo();
                        ui.Cj_id = row["Cj_id"].ToString();
                        ui.XL_id = row["XL_id"].ToString();
                        ui.Mingcheng = row["Mingcheng"].ToString();
                        XlInfoList.Add(ui);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return XlInfoList;
        }

        /// <summary>
        /// 获取型材表信息
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        public List<XingCaiInfo> getXcInfoList(SqlConnection conn)
        {
            List<XingCaiInfo> XcInfoList = new List<XingCaiInfo>();
            string sql = "SELECT Xc_id,Xl_id,MingchengXC,Daima,Mizhong,ChangDu,JiaGe,LB_id,Cj_ID,YS  FROM 型材 where Xc_id <>1";
            try
            {
                DataTable dt = db.Squery(sql, conn);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        XingCaiInfo ui = new XingCaiInfo();
                        ui.Xc_id = row["Xc_id"].ToString();
                        ui.Xl_id = row["Xl_id"].ToString();
                        ui.MingchengXC = row["MingchengXC"].ToString();
                        ui.Daima = row["Daima"].ToString();
                        ui.Mizhong = row["Mizhong"].ToString();
                        ui.ChangDu = row["ChangDu"].ToString();
                        ui.JiaGe = row["JiaGe"].ToString();
                        ui.LB_id = row["LB_id"].ToString();
                        ui.Cj_ID = row["Cj_ID"].ToString();
                        ui.YS = row["YS"].ToString();
                        XcInfoList.Add(ui);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return XcInfoList;
        }
        /// <summary>
        /// 获取型材表型材详细信息
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        public XingCaiInfo getXcDetailInfo(SqlConnection conn,string Xc_id)
        {
            XingCaiInfo XcInfo = new XingCaiInfo();
            string sql = "SELECT Xc_id,Xl_id,MingchengXC,Daima,ChangDu,JiaGe,LB_id,Cj_ID,YS  FROM 型材 where Xc_id = "+Xc_id;
            try
            {
                DataTable dt = db.Squery(sql, conn);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        XingCaiInfo ui = new XingCaiInfo();
                        ui.Xc_id = row["Xc_id"].ToString();
                        ui.Xl_id = row["Xl_id"].ToString();
                        ui.MingchengXC = row["MingchengXC"].ToString();
                        ui.Daima = row["Daima"].ToString();
                        ui.ChangDu = row["ChangDu"].ToString();
                        ui.JiaGe = row["JiaGe"].ToString();
                        ui.LB_id = row["LB_id"].ToString();
                        ui.Cj_ID = row["Cj_ID"].ToString();
                        ui.YS = row["YS"].ToString();
                        XcInfo = ui;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return XcInfo;
        }
        /// <summary>
        /// 获取配件表信息
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        public List<PeiJianInfo> getPjInfoList(SqlConnection conn)
        {
            List<PeiJianInfo> PjInfoList = new List<PeiJianInfo>();
            string sql = "SELECT Pj_id,Cj_id,Daima,Mingcheng,Guige,Danwei,Danjia,LB_id  FROM 配件 ";
            try
            {
                DataTable dt = db.Squery(sql, conn);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        PeiJianInfo ui = new PeiJianInfo();
                        ui.Cj_id = row["Cj_id"].ToString();
                        ui.Pj_id = row["Pj_id"].ToString();
                        ui.Daima = row["Daima"].ToString();
                        ui.Mingcheng = row["Mingcheng"].ToString();
                        ui.Guige = row["Guige"].ToString();
                        ui.Danwei = row["Danwei"].ToString();
                        ui.Danjia = row["Danjia"].ToString();
                        ui.LB_id = row["LB_id"].ToString();
                        PjInfoList.Add(ui);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return PjInfoList;
        }
        /// <summary>
        /// 获取配件表详细信息
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        public PeiJianInfo getPjDetailInfo(SqlConnection conn,string Pj_id)
        {
            PeiJianInfo PjInfo = new PeiJianInfo();
            string sql = "SELECT Pj_id,Cj_id,Daima,Mingcheng,Guige,Danwei,Danjia,LB_id  FROM 配件 where Pj_id = "+Pj_id;
            try
            {
                DataTable dt = db.Squery(sql, conn);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        PeiJianInfo ui = new PeiJianInfo();
                        ui.Cj_id = row["Cj_id"].ToString();
                        ui.Pj_id = row["Pj_id"].ToString();
                        ui.Daima = row["Daima"].ToString();
                        ui.Mingcheng = row["Mingcheng"].ToString();
                        ui.Guige = row["Guige"].ToString();
                        ui.Danwei = row["Danwei"].ToString();
                        ui.Danjia = row["Danjia"].ToString();
                        ui.LB_id = row["LB_id"].ToString();
                        PjInfo = ui; ;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return PjInfo;
        }
        /// <summary>
        /// 获取玻璃表信息
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        public List<BoLiInfo> getBlInfoList(SqlConnection conn)
        {
            List<BoLiInfo> BlInfoList = new List<BoLiInfo>();
            string sql = "SELECT Bl_id,Cj_id,Daima,Changdu,Kuandu,HouDu,YanSe,DanJia  FROM 玻璃";
            try
            {
                DataTable dt = db.Squery(sql, conn);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        BoLiInfo ui = new BoLiInfo();
                        ui.Bl_id = row["Bl_id"].ToString();
                        ui.Cj_id = row["Cj_id"].ToString();
                        ui.Daima = row["Daima"].ToString();
                        ui.Changdu = row["Changdu"].ToString();
                        ui.Kuandu = row["Kuandu"].ToString();
                        ui.HouDu = row["HouDu"].ToString();
                        ui.YanSe = row["YanSe"].ToString();
                        ui.DanJia = row["DanJia"].ToString();
                        BlInfoList.Add(ui);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return BlInfoList;
        }
    }
}
